﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GuidGeneratorSilverlight
{
	public partial class GuidCountWindow : ChildWindow
	{
		public GuidCountWindow(Options options)
		{
			InitializeComponent();

			this.DataContext = options;
		}

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{
			this.DialogResult = true;
		}

		private void CancelButton_Click(object sender, RoutedEventArgs e)
		{
			this.DialogResult = false;
		}

		private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
		{
			this.textBoxCount.Focus();
			this.textBoxCount.SelectAll();
		}

		private void ChildWindow_KeyDown(object sender, KeyEventArgs e)
		{
			switch (e.Key)
			{
				case Key.Enter:
					if (this.OKButton.IsEnabled)
						this.DialogResult = true;
					break;

				case Key.Escape:
					this.DialogResult = false;
					break;
			}
		}

		private void textBoxCount_TextChanged(object sender, TextChangedEventArgs e)
		{
			var be = this.textBoxCount.GetBindingExpression(TextBox.TextProperty);
			be.UpdateSource();
		}
	}
}

